package com.lo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lo.common.JsonResult;
import com.lo.dao.AdminMapper;
import com.lo.dao.UserMapper;
import com.lo.entity.Admin;
import com.lo.entity.CourseWithTCHName;
import com.lo.entity.User;
import com.lo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo selectAllExaminedCourse(int pageNum, int pageSize,String search) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseWithTCHName> courseWithTCHNameList = adminMapper.selectAllExaminedCourse(search);
        System.out.println(courseWithTCHNameList);
        PageInfo pageInfo = new PageInfo(courseWithTCHNameList);
        return pageInfo;
    }

    @Override
    public PageInfo selectAllNotExamineCourse(int pageNum, int pageSize, String search) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseWithTCHName> courseWithTCHNameList = adminMapper.selectAllNotExamineCourse(search);
//        System.out.println();
        PageInfo pageInfo = new PageInfo(courseWithTCHNameList);
        return pageInfo;
    }

    @Override
    public PageInfo selectAllDeletingCourse(int pageNum, int pageSize, String search) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseWithTCHName> courseWithTCHNameList = adminMapper.selectAllDeletingCourse(search);
        PageInfo pageInfo = new PageInfo(courseWithTCHNameList);
        return pageInfo;
    }

    @Override
    public JsonResult login(String username, String password) {
        List<Admin> admins = adminMapper.selectByUsernameAndPassword(username,password);
        if (admins.size()<=0){
            return new JsonResult(3,"用户名或密码错误",null);
        }
        return new JsonResult(0,"管理员登陆成功",admins.get(0));
    }

    @Override
    public PageInfo selectAllCourse(int pageNum, int pageSize, String search, String controllInfo) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseWithTCHName> courseWithTCHNameList = new ArrayList<>();
        switch (controllInfo){
            case "1":
                //所有审核过的课程
                courseWithTCHNameList=adminMapper.selectAllExaminedCourse(search);
                break;
            case "3":
                //所有未审核的课程
                courseWithTCHNameList=adminMapper.selectAllNotExamineCourse(search);
                break;
            case "5":
                //所有待删除课程
                courseWithTCHNameList = adminMapper.selectAllDeletingCourse(search);
                break;
        }
//        System.out.println(courseWithTCHNameList);
        PageInfo pageInfo = new PageInfo(courseWithTCHNameList);
        return pageInfo;

    }


}
